
class StateModel

    attr_reader :info

    def initialize()
        if (!File.exist?(Settings.state))
            @info={:last_saved=>0, :total=>0, :last_md5=>nil,:last_size=>0}
            @stateFile=File.new(Settings.state, 'w+')
        else
            @stateFile=File.open(Settings.state, 'r+')
            @info=YAML::load(@stateFile)
        end
    end

    def commit(result)
        @info.last_saved+=1
        @info.last_md5=result.md5
        @info.total+=result.size
        @info.last_size=result.size
        @stateFile.truncate(@info.to_yaml.length)# each letter is one byte long?
        @stateFile.pos=0
        @stateFile.puts(@info.to_yaml)
        @stateFile.flush
    end
end
